<?php
class SupportworkerModel extends Orm_Base{
    public $table = 'support_worker';
    public $field = array(
        'id' => array('type' => "int(11) unsigned",'comment' => ''),
        'username' => array('type' => "varchar(45)",'comment' => '账号'),
        'name' => array('type' => "varchar(45)",'comment' => '姓名'),
        'password' => array('type' => "varchar(32)",'comment' => ''),
        'created' => array('type' => "int(11)",'comment' => ''),
        'updated' => array('type' => "int(11)",'comment' => ''),
        'private_key' => array('type' => "varchar(4)",'comment' => '加密私钥'),
        'sid' => array('type' => "varchar(45)",'comemnt' => '关联老年人ID(一个护工可以对应多个老人,例如：1,2,3)'),
    );
    public $pk = 'id';
    //创建TOKEN
    public function creattoken($sw_id){
        $tTime = time();
        $tEndtime = ($tTime+86400*7);
        
        $tToken = md5(md5($sw_id) . $tTime . 'lylpyp');
        $tMO = new SupportworkertokenModel;
        $tData = array(
            'created' => $tTime,
            'token' => $tToken,
            'sw_id' => $sw_id,
            'endtime' => $tEndtime,
        );
        $tMO->insert($tData);
        return array('token' => $tToken,'sw_id' => $sw_id);
    }
}
?>
